using System;
using System.Collections.Generic;
using System.Text;
using MULENetworking;

namespace MULEServer
{
    public class Store : IStore
    {
        # region vars
        protected int foodUnits;
        protected int foodPrice;
        protected int energyUnits;
        protected int energyPrice;
        protected int smithoreUnits;
        protected int smithorePrice;
        protected int crystiteUnits;
        protected int crystitePrice;
        protected int muleUnits;
        protected int mulePrice;
        # endregion

        #region IStore Members

        public int FoodUnits
        {
            get
            {
                return foodUnits;
            }
            set
            {
                foodUnits = value;
            }
        }

        public int FoodPrice
        {
            get
            {
                return foodPrice;
            }
            set
            {
                foodPrice = value;
            }
        }

        public int EnergyUnits
        {
            get
            {
                return energyUnits;
            }
            set
            {
                energyUnits = value;
            }
        }

        public int EnergyPrice
        {
            get
            {
                return energyPrice;
            }
            set
            {
                energyPrice = value;
            }
        }

        public int SmithoreUnits
        {
            get
            {
                return smithoreUnits;
            }
            set
            {
                smithoreUnits = value;
            }
        }

        public int SmithorePrice
        {
            get
            {
                return smithorePrice;
            }
            set
            {
                smithorePrice = value;
            }
        }

        public int CrystiteUnits
        {
            get
            {
                return crystiteUnits;
            }
            set
            {
                crystiteUnits = value;
            }
        }

        public int CrystitePrice
        {
            get
            {
                return crystitePrice;
            }
            set
            {
                crystitePrice = value;
            }
        }

        public int MuleUnits
        {
            get
            {
                return muleUnits;
            }
            set
            {
                muleUnits = value;
            }
        }

        public int MulePrice
        {
            get
            {
                return mulePrice;
            }
            set
            {
                mulePrice = value;
            }
        }

        #endregion

        public Store()
        {
            FoodUnits = 8;
            FoodPrice = 25;
            EnergyUnits = 8;
            EnergyPrice = 25;
            SmithoreUnits = 8;
            SmithorePrice = 50;
            CrystiteUnits = 0;
            CrystitePrice = 100;
            MuleUnits = 14;
            MulePrice = 100;
        }

        public void buyFood(IPlayer player)
        {
            if(foodUnits > 0 && player.money >= (FoodPrice+ 35)) 
            {
                player.food++;
                player.money -= (FoodPrice + 35);
            }
        }

        public void sellFood(IPlayer player)
        {
            if (player.food > 0)
            {
                player.food--;
                player.money += (FoodPrice);
            }
        }

        public void buyEnergy(IPlayer player)
        {
            if (energyUnits > 0 && player.money >= (EnergyPrice + 35))
            {
                player.energy++;
                player.money -= (EnergyPrice + 35);
            }
        }

        public void sellEnergy(IPlayer player)
        {
            if (player.energy > 0)
            {
                player.energy--;
                player.money += EnergyPrice;
            }
        }

        public void buySmithore(IPlayer player)
        {
            if (SmithoreUnits > 0 && player.money >= (SmithorePrice + 50))
            {
                player.smithore++;
                player.money -= (SmithorePrice + 50);
            }
        }

        public void sellSmithore(IPlayer player)
        {
            if (player.energy > 0)
            {
                player.energy--;
                player.money += SmithorePrice;
            }
        }

        public void buyCrystite(IPlayer player)
        {
            if (CrystiteUnits > 0 && player.money >= (CrystitePrice + 140))
            {
                player.crystite++;
                player.money -= (CrystitePrice + 140);
            }
        }

        public void sellCrystite(IPlayer player)
        {
            if (player.crystite > 0)
            {
                player.crystite--;
                player.money += CrystitePrice;
            }
        }

        public void buyMule(IPlayer player)
        {
            if(MuleUnits > 0 && player.money >= MulePrice)
            {
                player.hasMule = true;
                player.money -= MulePrice;
            }
        }

        public void equipMule(IPlayer player, string equipMule)
        {
            switch(equipMule)
            {
                case "food":
                    if(player.money >= 25)
                    {
                        player.muleType = "food";
                        player.money -= 25;
                    }
                    break;
                case "energy":
                    if(player.money >= 50)
                    {
                        player.muleType = "energy";
                        player.money -= 50;
                    }
                    break;
                case "smithore":
                    if(player.money >= 75)
                    {
                        player.muleType = "smithore";
                        player.money -= 75;
                    }
                    break;
                case "crystite":
                    if(player.money >= 100)
                    {
                        player.muleType = "crystite";
                        player.money -= 100;
                    }
                    break;
            }

             /* GAMBLING: NYI
              * need info on how the turn timer is gonna work.
              */
        }



    }
}
